package com.ly.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ly.bean.EasybuySeller;
import com.ly.mapper.EasybuySellerMapper;
import com.ly.service.SellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 李岩
 * @date 2021/12/14-16:21
 * @describe
 */
@Component
@Service(interfaceClass = SellerService.class)
public class SellerServiceImpl implements SellerService {
    private final Logger logger= LoggerFactory.getLogger(SellerServiceImpl.class);
    @Autowired
    private EasybuySellerMapper sellerMapper;
    private SellerServiceImpl(){
        System.out.println("进入了卖家的  service层");
    }

    /**
     * 根据卖家名查询卖家对象
     */
    public EasybuySeller selectByPrimaryKey(String sellerId) throws Exception{
        logger.info("卖家登录的service层   "+sellerId);
        EasybuySeller easybuySeller = sellerMapper.selectByPrimaryKey(sellerId);
        return easybuySeller;
    }

    /**
     * 查询所有商家
     */
    public PageInfo<EasybuySeller> selectAllSeller(String pageNum,String pageSize) throws Exception{
        int pageNumInt=1;
        int pageSizeInt=5;
        if (pageNum!=null && !"".equals(pageNum)){
            pageNumInt=Integer.valueOf(pageNum);
        }
        if (pageSize!=null && !"".equals(pageSize)){
            pageSizeInt=Integer.valueOf(pageSize);
        }
        PageHelper.startPage(pageNumInt,pageSizeInt);
        List<EasybuySeller> list = sellerMapper.selectAllSeller();
        PageInfo<EasybuySeller> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
